package com.ibeetl.admin.core.service;


import com.ibeetl.admin.core.dao.CoreFileDao;
import com.ibeetl.admin.core.entity.CoreFile;
import com.ibeetl.cms.entity.CmsArticle;
import com.ibeetl.cms.web.query.CoreFileQuery;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * CoreLog Service
 */

@Service
@Transactional
public class CoreFileService extends CoreBaseService<CoreFile>{

    @Autowired private CoreFileDao coreFileDao;

    @Cacheable(CorePlatformService.COREFILE_CACHE_BATCHID)
    public List<CoreFile> queryByBatchId(String fileBatchId) {
        CoreFile template=new CoreFile();
        template.setFileBatchId(fileBatchId);

        List<CoreFile> dbDatas = coreFileDao.template(template);
        return  dbDatas;
    }

    /**
     * 此方法使用CoreFileQuery作为参数，是因为使用PageQuery作为参数时无法用toString方法，导致无法使用缓存
     */
    @Cacheable(value = CorePlatformService.ARTICLE_QUERYBYCONDITION_CACHE)
    public PageQuery<CmsArticle> queryByCoreFileQuery(CoreFileQuery condition, Long pageSize, Long pageNo) {
        PageQuery<CoreFile> page = condition.getPageQuery();
        page.setPageSize(pageSize);
        page.setPageNumber(pageNo);
        PageQuery ret =  coreFileDao.queryByCondition(page);
        queryListAfter(ret.getList());
        return ret;
    }
}